<template>
	<view class="container">
		<view class="topVue">
			<view class="tabVue flex-center margin20">
				<view class="tab" :class="{active: current===''}" @click="change('')">全部</view>
				<view class="tab" :class="{active: current===0}" @click="change(0)">待盘点</view>
				<view class="tab" :class="{active: current===1}" @click="change(1)">已盘点</view>
				<view class="tab" :class="{active: current===2}" @click="change(2)">已取消</view>
				<!-- <view class="tab" :class="{active: current===4}" @click="change(4)"></view> -->
			</view>
			<view class="searchVue margin20 flex-between align-center padding-row30">
				<input type="text" placeholder="搜索盘点单号" placeholder-style="font-size: 28rpx;" v-model="orderNum" @input="input"/>
				<image src="/static/search.png" style="width: 40rpx; height: 40rpx;" @click="searchFun"></image>
			</view>
		</view>
		<view style="height: 220rpx;"></view>
		
		<view class="itemVue margin20">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="top flex-between align-center">
					<view class="flex align-center">
						<text style="color: #666; font-size: 28rpx;">盘点单号:</text>
						<text style="color: #0052D9; font-size: 28rpx;">{{ item.stocktakingTaskNo }}</text>
					</view>
					<view class="state" 
						:style="{background: ['#F3E8DC', '#E8F8F2', '#E7E7E7'][item.status], color: ['#ED7B2F', '#52A870', '#391818'][item.status] }"
						>
						{{ ['待盘点', '已盘点', '已取消'][item.status] }}
					</view>
				</view>
				<view class="center padding30">
					<view class="flex">
						<view class="w33 flex align-center">
							<text style="color: #666;">盘点门仓：</text>
							<text style="color: #222;">{{ item.storeName}}</text>
						</view>
						<view class="w33 flex align-center">
							<text style="color: #666;">盘点备注：</text>
							<text style="color: #222;">{{ item.reason }}</text>
						</view>
						<view class="w33 flex-end align-center">
							<text style="color: #666;">盘点截至日期：</text>
							<text style="color: #222;">{{ item.deadline }}</text>
						</view>
					</view>
					<view class="flex margin30">
						<view class="w33 flex align-center">
							<text style="color: #666;">应盘数量：</text>
							<text style="color: #222;">{{ item.expectStock }}</text> 
						</view>
						<view class="w33 flex align-center">
							<text style="color: #666;">实盘数量：</text>
							<text style="color: #222;">{{ item.actualStock || "--" }}</text> 
						</view>
						<view class="w33 flex-end align-center">
							<text style="color: #666;">创建时间：</text>
							<text style="color: #222;">{{ item.createTime }}</text>
						</view>
					</view>
				</view>
				<view class="bot flex-end align-center padding-row30">
					<view class="btn" @click="toDetail(item)">盘点商品</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getStocktasking } from "@/api";
	export default {
		data() {
			return {
				current: "",
				orderNum: "",
				page: 1,
				limit: 10,
				isLastPage: false,
				list: []
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if(this.isLastPage) return
			this.page++
			this.getList()
		},
		methods: {
			change(index){
				this.current = index
				this.list = []
				this.page = 1
				this.getList()
			},
			input(){
				if(!this.orderNum) this.searchFun()
			},
			searchFun(){
				this.list = [] 
				this.page = 1
				this.getList()
			},
			getList(){
				uni.showLoading()
				getStocktasking({
					page: this.page, 
					limit: this.limit,
					status: this.current,
					stocktakingTaskNo: this.orderNum
				}).then(res=>{
					console.log("kkkkk", res.data.list)
					uni.hideLoading()
					this.list = this.list.concat(res.data.list)
					this.isLastPage = res.data.totalPage == this.page
					console.log("盘点任务列表", this.list)
				}).catch(()=>{
					uni.hideLoading()
				})
			},
			toDetail(item){
				uni.navigateTo({
					url: "./inventoryDetail?id=" + item.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		.topVue {
			width: 100%;
			background: #fff;
			position: fixed;
			left: 0;
			top: 0;
			padding: 0 30rpx;
			z-index: 99;
			padding-bottom: 20rpx;
			.tabVue {
				width: 690rpx;
				height: 80rpx;
				background: #f8f8f8;
				border-radius: 10rpx;
				padding: 5rpx;
				.tab {
					width: 25%;
					height: 70rpx;
					color: #333;
					font-size: 28rpx;
					line-height: 70rpx;
					text-align: center;
				}
				.active {
					background: #0052D9;
					border-radius: 10rpx;
					color: #fff;
				}
			}
	
			.searchVue {
				width: 100%;
				height: 80rpx;
				background: #f8f8f8;
				border-radius: 10rpx;
			}
		}
		.itemVue {
			width: 100%;
			padding: 0 30rpx 1rpx;
			background: #fff;
			.item {
				width: 100%;
				border: 1rpx solid #f8f8f8;
				border-radius: 14rpx;
				margin-bottom: 20rpx;
				.top {
					width: 100%;
					height: 100rpx;
					padding: 0 30rpx;
					border-bottom: 1rpx solid #f8f8f8;
					.state {
						width: 120rpx;
						height: 50rpx;
						border-radius: 10rpx;
						line-height: 50rpx;
						text-align: center;
						font-size: 28rpx;
					}
				}
				.bot {
					width: 100%;
					height: 100rpx;
					padding: 0 30rpx;
					border-top: 1rpx solid #f8f8f8;
					.btn {
						width: 180rpx;
						height: 76rpx;
						text-align: center;
						line-height: 76rpx;
						background: #0052D9;
						border-radius: 38rpx;
						color: #fff;
						font-size: 28rpx;
					}
				}
			}
		}
	}
</style> 